/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



package bsc.war.form;


import bsc.ejb.metadata.Unit;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author luisZavaleta
 */
public class SelectUnit extends AbstractController{

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");
        ModelAndView mav = new ModelAndView("selectUnit");

        try {
            Unit unit = null;

            if (NumberUtils.isDigits(request.getParameter("unitId"))) {
                unit = delegate.findUnit(Long.valueOf(request.getParameter("unitId")));
            }

            mav.addObject("unit", unit);
        } catch (Exception e) {
        }

        return mav;
    }

}
